<?php
/**
 * Validierungsklasse zur Parametervalidierung
 *
 * @author		Joachim Ruf
 * @copyright	Copyright (c) 2003-2013 Loresoft Software (http://www.loresoft.de)
 * @license		http://yapary.loresoft.de/lizenzbedingungen     New BSD License
 *
 * */


/**
 * $val muss einer Zahlenfolge entsprechen
 * Format {PATTERN}/{MODIFIER}
 * */
Class Yapary_Parameter_CheckPattern Extends Yapary_Exception_Error Implements Yapary_Parameter_ICheck
{
	private $pattern, $patternModifier;
	function __construct ( $_pattern, $_patternModifier = '' )
	{
		$this->pattern			= $_pattern;
		$this->patternModifier	= $_patternModifier;
	}


	public function typedef ( $val )
	{
		return (string) $val;
	}


	public function getPattern ()
	{
		return $this->pattern;
	}


	public function isValid ( $val )
	{
		if (!preg_match('/'.$this->getPattern().'/'.$this->patternModifier, $val)) {
			$this->addError(Yapary_Exception_Error::E_WRONG_FORMAT);
			return false;
		}

		return true;
	}
}
